import RequestUtils from '@/utils/RequestUtils'

const groupName = 'gen'
const apiName = 'genTable'

export default {
  /**
   * 导入数据库表结构
   * @param params
   * @returns {AxiosPromise}
   */
  importTable(params = {}) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/importTable`,
      method: 'POST',
      params: params
    })
  },
  remove(ids) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/${ids}`,
      method: 'DELETE'
    })
  },
  edit(data) {
    return RequestUtils({
      url: `/${groupName}/${apiName}`,
      method: 'put',
      data: data
    })
  },
  get(id) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/${id}`,
      method: 'GET'
    })
  },
  getTableColumnList(tableName) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/getTableColumnList/${tableName}`,
      method: 'GET'
    })
  },
  list(params = {}) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/search}`,
      method: 'POST',
      data: {
        ...params
      }
    })
  },
  page(params = {}, page) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/search/${page.current}/${page.pageSize}`,
      method: 'POST',
      data: {
        ...params
      }
    })
  },
  /**
   * 数据库表-列表
   * @param params
   * @returns {AxiosPromise}
   */
  dbTableList(params = {}, page) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/search/dbTableList/${page.current}/${page.pageSize}`,
      method: 'POST',
      data: {
        ...params
      }
    })
  },
  /**
   * 预览生成代码
   * @param id
   * @returns {AxiosPromise}
   */
  preview(id) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/preview/${id}`,
      method: 'GET'
    })
  },
  /**
   * 生成代码（自定义路径）
   * @param query
   * @returns {AxiosPromise}
   */
  genCode(tableName) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/genCode/${tableName}`,
      method: 'GET'
    })
  },
  /**
   * 同步数据库表结构
   * @param tableName
   * @returns {AxiosPromise}
   */
  syncDbTable(tableName) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/syncDbTable/${tableName}`,
      method: 'GET'
    })
  }
}
